#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *first_thread(void *arg) {
    printf("first_thread线程(%d)开始执行\n",gettid());
    return NULL;
}
void *second_thread(void *arg) {
    printf("second_thread线程(%d)开始执行\n",gettid());
    return NULL;
}
int main(int argc, char *argv[]) {
    printf("main线程(%d)开始执行\n",gettid());
    //创建分线程（自动会执行）
    pthread_t pt1,pt2;
    pthread_create(&pt1,NULL,first_thread,NULL);
    pthread_create(&pt2,NULL,second_thread,NULL);
    printf("create之后main线程(%d)继续执行,pt1=%ld,pt2=%ld\n",gettid(),pt1,pt2);

    //main线程需要最后一个结束
    //等待分线程执行完毕
    pthread_join(pt1,NULL);
    pthread_join(pt2,NULL);
    printf("main线程(%d)结束\n",gettid());
    return 0;
}